<?php

/**
 * @Author: wuchenge
 * @Date:   2022-04-26 15:21:46
 * @Email: ligui0506@126.com
 * @Descript:
 */
namespace App\Requests;

use Illuminate\Http\Request;

class ArticleRequest extends FormRequest
{
    public function rules(Request $request)
    {
        $params = $request->input();
        $id     = 0;
        if (array_key_exists('id', $params)) {
            $id = $params['id'];
        }
        return [
            'title'     => [
                'required',
                'unique:articles,title,' . $id,
            ],
            'thumb'     => [
                'required',
            ],
            'content'   => [
                'required',
            ],
            'status'    => [
                'required',
                'in:1,2',
            ],
            'label_ids' => [
                'required',
                'array',
            ],
            'id'        => [
                'required',
                'integer',
                'gt:0',
            ],

        ];
    }

    public function messages()
    {
        return [
            'title.required'     => '100301',
            'title.unique'       => '100302',
            'thumb.required'     => '100303',
            'content.required'   => '100304',
            'status.required'    => '100305',
            'status.in'          => '100306',
            'id.required'        => '100307',
            'id.integer'         => '100308',
            'id.gt'              => '100309',
            'label_ids.required' => '100310',
            'label_ids.array'    => '100311',
        ];
    }

    public $scene = [
        'admin.article.add'    => ['title', 'thumb', 'status', 'content', 'label_ids'],
        'admin.article.modify' => ['title', 'thumb', 'status', 'content', 'label_ids', 'id'],
    ];
}
